package com.tr.rentcar.controller.houtai.admin;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tr.rentcar.model.bean.Adminrole;
import com.tr.rentcar.model.dao.AdminDao;
import com.tr.rentcar.model.dao.AdminroleDao;

@WebServlet("/adminmodify")
public class AdminModifyControllor extends HttpServlet {
	AdminroleDao adminroledao = new AdminroleDao();
	AdminDao admindao = new AdminDao();
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			req.setCharacterEncoding("utf-8");
			String id = req.getParameter("aid");
			Integer aid = Integer.parseInt(id);
			String aname = req.getParameter("aname");
			String anickname = req.getParameter("anickname");
			String asex = req.getParameter("asex");
			String atel = req.getParameter("atel");
			String arname = req.getParameter("arname");
			Adminrole adminrole = adminroledao.findallbyname(arname);
			Integer arid = adminrole.getAr_id();
			admindao.updateadmin(aname, anickname, asex, atel, arid, aid);

		} catch (SQLException e) {
			e.printStackTrace();
		}
		resp.sendRedirect(req.getContextPath() + "/houtaiadmin");
	}
}
